package com.kunbo.cn.controller.core.otherbusiness;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.kunbo.cn.entity.core.otherbusiness.OtherWarehousingNotice;
import com.kunbo.cn.service.core.otherbusiness.OtherWarehousingNoticeService;
import com.kunbo.cn.util.date.SDate;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.BuildBean1;
import com.kunbo.cn.util.retu.CommonResult;
import com.kunbo.cn.util.retu.Pages;
import com.kunbo.cn.util.retu.ResultBean;
import com.kunbo.cn.util.retu.ResultBean1;

/**
 * 其它入库通知单
 * @author bjl
 *
 */
@RestController
@RequestMapping("/OtherWarehousingNotice")
public class OtherWarehousingNoticeController {
	@Autowired
	private JdbcTemplate jdbc;
	@Autowired
	private OtherWarehousingNoticeService service;
	/**
	 * 添加其它入库通知单
	 * 
	 */
	@PostMapping("/add")
	public CommonResult add(OtherWarehousingNotice Notice) {
		service.save(Notice);
		return new CommonResult(true,"操作成功",null);
	}
	/**
	 * 通知单编号自动生成
	 * @return
	 */
	@GetMapping("/createCode")
	public String createCode(){
		 String prex = "TZDH";
		 String bill_code= prex+SDate.getSystemDateYMDHMSToString();
		 return bill_code;
	}
	/*@GetMapping("/cardSerial")
	public String getCardSerial(){
		 String prex = "RK";
		 String card_serial= prex+SDate.getSystemDateYMDHMSToString();
		 return card_serial;
	}*/
		/**
		 * 
		 * 修改
		 */
		@PutMapping("/update")
		public CommonResult update(OtherWarehousingNotice Notice) {
			service.update(Notice);
			return new CommonResult(true,"操作成功",null);
		}
		
		@DeleteMapping("/delete")
		public CommonResult delete(Integer id) {
			service.delete(id);
			return new CommonResult(true,"操作成功",null);
		}
		/**
		 * 详情
		 * 
		 */
		@GetMapping("/findById")
		public OtherWarehousingNotice findById(Integer id) {
			OtherWarehousingNotice Notice = service.findById(id);
			return Notice;
		}
		
		@GetMapping("/list")
		public ResultBean1<Pages> exelist(
				@RequestParam String startTime,
				@RequestParam String endTime,
				@RequestParam String supplier,
				@RequestParam String receiving_unit,
				@RequestParam String warehouse,//仓库
				@RequestParam String materiel,//物料
				@RequestParam String mater_type,//物料类型  
				@RequestParam String car_number,
				@RequestParam Integer page,
				@RequestParam Integer pageSize
				){
			ResultBean1<Pages> result  = new ResultBean1<Pages>();
			return BuildBean1.buildResulttoPages(result, "success", "error", service.list(startTime,endTime,supplier,receiving_unit,warehouse,materiel,mater_type,car_number,page,pageSize));
		}
		/**
		 * 获取车号信息列表
		 * @return
		 */
		@PostMapping("/getCarInfo")
		public ResultBean<List<Map<String,Object>>> getCarInfo(
				@RequestParam String id
				){
			ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
			return BuildBean.buildResult(result, "success", "error", service.getCarInfo(id));
		}
		
		/**
		 * 
		 * 审核状态接口
		 */
		@GetMapping("/updateState")
		public CommonResult updateState( Integer id ,String audit_status) {
			service.updateState(id,audit_status);
			return new CommonResult(true,"操作成功",null);
		}
		/**
		 * 获取供应商
		 * 
		 */
		@PostMapping("/getSuppliers")
		public ResultBean<List<Map<String,Object>>> getSuppliers(){
			ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
			return BuildBean.buildResult(result, "success", "error", service.getSuppliers());
		}
		/**
		 * 获取物料id，name
		 * 
		 */
		@PostMapping("/matterid")
		public ResultBean<List<Map<String,Object>>>matter(
				){
			ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
			return BuildBean.buildResult(result, "succes", "error",service.matterid());
		}
		/**
		 * 获取物料级联物料类型
		 * 
		 */
		@PostMapping("/getMatter")
		public ResultBean<List<Map<String,Object>>>getMatter(
				@RequestParam("mater_type")String mater_type
				){
			ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
			return BuildBean.buildResult(result, "succes", "error",service.getMatter(mater_type));
		}
		/**
		 * 获取组织管理(即入库通知单中的收货单位)
		 */
		@PostMapping("/getOrganizations")
		public ResultBean<List<Map<String,Object>>> getOrganizations(){
			ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
			return BuildBean.buildResult(result, "succes", "error",service.getOrganizations());
		}
		/**
		 * 获取司机
		 * 
		 */
		@PostMapping("/carDriver")
		public ResultBean<List<Map<String,Object>>> carDriver(
				){
			ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
			return BuildBean.buildResult(result, "succes", "error",service.carDriver());
		}

		/**
		 * 获取车牌号
		 * 
		 */
		@PostMapping("/carNumber")
		public ResultBean<List<Map<String,Object>>> carNumber(
				){
			ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
			return BuildBean.buildResult(result, "succes", "error",service.carNumber());
		}
		/**
		 * 获取仓库
		 * 
		 */
		@PostMapping("/depot")
		public ResultBean<List<Map<String,Object>>> depot(
				){
			ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
			return BuildBean.buildResult(result, "succes", "error",service.depot());
		}
		/**
		 * 获取提醒状态
		 * 
		 */
		@PostMapping("/reminderStatus")
		public ResultBean<List<Map<String,Object>>>reminderStatus(
				){
			ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
			return BuildBean.buildResult(result, "succes", "error",service.reminderStatus());
		}
}
